<!-- EMI ------->
<script type="text/javascript">
    function getXMLHTTP() { //fuction to return the xml http object
        var xmlhttp=false;	
        try{
            xmlhttp=new XMLHttpRequest();
        }
        catch(e)	{		
            try{			
                xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){
                try{
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e1){
                    xmlhttp=false;
                }
            }
        }
		 	
        return xmlhttp;
    }
            
    function validate(){
        var iChars = "0123456789.";
        for (var i = 0; i < document.getElementById('principal').value.length; i++) {
            if (iChars.indexOf(document.getElementById('principal').value.charAt(i)) == -1) {
                alert ("Only Number allowed.");
                document.getElementById('principal').focus( );
                return false;
            }
        }
        if ( document.getElementById('principal').value == "" )
        {
            alert( "Please Enter Pricipal Amount." );
            document.getElementById('principal').focus( );
            return false;
        }
        if ( document.getElementById('period').value == "" )
        {
            alert( "Please Enter EMI Period." );
            document.getElementById('period').focus( );
            return false;
        }
                
        for (var i = 0; i < document.getElementById('interest').value.length; i++) {
            if (iChars.indexOf(document.getElementById('interest').value.charAt(i)) == -1) {
                alert ("Only Number/Currency allowed in Interest rate.");
                document.getElementById('interest').focus( );
                return false;
            }
        }
        if ( document.getElementById('interest').value == "" )
        {
            alert( "Please Enter Rate of Interest." );
            document.getElementById('interest').focus( );
            return false;
        }
        return true;
    }
            
    function emi_calculator(baseUrl,p,r,n) {		
        //--Validate form --//
        if (validate())
        {
            var strURL=baseUrl+"emi/emi_calculator?p="+p+"&r="+r+"&n="+n;
            var imgURL = baseUrl+"images/loading4.gif";
            //alert (imgURL);
            var req = getXMLHTTP();
            if (req) {
                req.onreadystatechange = function() {
                    $("#emidiv").html('Please wait...');
                            
                    if (req.readyState == 4) {
                        // only if "OK"
                        if (req.status == 200) {						
                            document.getElementById('emidiv').innerHTML=req.responseText;						
                        } else {
                            alert("There was a problem while Calculating EMI:\n" +baseUrl);
                        }
                    }				
                }			
                req.open("GET", strURL, true);
                req.send(null);
            }

        }
    }
        
</script>

<?php
$banner_500_100 = $this->banner_model->get_banner('500X100');
?>

<div class="grid_6">
    <div class="tabs tabs_var1">
        <ul class="nav">
            <li class="selected"><a href="#car_tab">EMI Calculator</a></li>
        </ul>
        <div class="clear"></div>
        <div class="tabs_1">
            <div id="car_tab" class="tab-content">
                <div class="inner" style="height:292px">
                    <form id="form-main" method="post" action="<?= base_url(); ?>search/search_car/used">
                        <div class="rowElem">
                            <div class="block-underline"  style="text-align: justify">
                                <h2>EMI Calculator - Calculate Your Loan Instalment</h2>
                                <label class="font_1">
                                    The calculation performed by EMI Calculator is based on the information you entered and is for illustrative purposes only. 
                                    This calculation reflects amounts in rounded to the nearest whole figure. 
                                    Estimated monthly payments DO NOT include any processing or other possible fees which may depend on the financial institution / banks.
                                    All loan figures are based upon non-commercial usage and are subject to credit approval from an independent lending source. 
                                    Actual down payment and resulting monthly payments may vary depending upon type and use of vehicle, regional lender requirements, and the strength of your credit. 
                                    Check with your dealer for exact monthly payment.
                                </label>
                            </div>
                            <div class="clear"></div>  

                            <div class="fleft" style="width: 140px">
                                <label><strong>Loan Amount:</strong></label>
                                <input id="principal" name="principal" type="text" style="width: 120px" ></input>
                            </div>

                            <div class="fleft" style="width: 110px">
                                <label><strong>Period:</strong></label>
                                <div id="modeldiv">
                                    <select id="period" name="period" style="width: 100px" >
                                        <option value="" selected>Months</option>
                                        <option value="12">12 Months</option>
                                        <option value="24">24 Months</option>
                                        <option value="36">36 Months</option>
                                        <option value="48">48 Months</option>
                                        <option value="60">60 Months</option>
                                        <option value="72">72 Months</option>
                                        <option value="84">84 Months</option>
                                        <option value="96">96 Months</option>
                                        <option value="108">108 Months</option>
                                        <option value="120">120 Months</option>
                                    </select>
                                </div>    
                            </div>

                            <div class="fleft" style="width: 60px; margin-right: 20px">
                                <label><strong>Int(Rate):</strong></label>
                                <input id="interest" name="interest" type="text" style="width: 50px" ></input>
                            </div>

                            <div class="fleft mid_col">
                                <a onClick="emi_calculator('<?= base_url(); ?>',document.getElementById('principal').value,document.getElementById('interest').value,document.getElementById('period').value);" class="inline-block button_search color_1 bold"><span class="inline-block">Calculate !</span></a>
                            </div>

                            <div class="clear"></div>
                            <div id="emidiv" style="margin: 25px 0px 25px 0px;"> </div>
                        </div>
                    </form>



                </div>
            </div>

        </div>
    </div>
</div>